package com.serkol.driving.learning.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@Primary
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyMetaObjectHandler.class);

    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println("start insert fill ....");
        LOGGER.info("start insert fill ....");
        this.strictInsertFill(metaObject, "createDate",Long.class, System.currentTimeMillis());
        this.setFieldValByName("createDate",System.currentTimeMillis(), metaObject);
        this.strictInsertFill(metaObject, "updateDate",Long.class, System.currentTimeMillis());
        this.setFieldValByName("updateDate",System.currentTimeMillis(), metaObject);
        this.setFieldValByName("date",System.currentTimeMillis(), metaObject);
        this.setFieldValByName("deleted", 0, metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {

        //this.strictInsertFill(metaObject, "updateDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateDate",Long.class, System.currentTimeMillis());
        this.setFieldValByName("updateDate",System.currentTimeMillis(), metaObject);
  this.setFieldValByName("updateDate",System.currentTimeMillis(), metaObject);

    }


}
